/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 任务
	/// module : structs
	/// </summary>
	public class QuestPOD : IPOD 
    {
        public readonly static Func<QuestPOD> FACTORY = () => new QuestPOD();
		public static Func<QuestPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 任务唯一id -- 服务器数据同步用
        /// </summary>
		public long id;
		/// <summary>
        /// 配置id
        /// </summary>
		public int cid;
		/// <summary>
        /// 进度
        /// </summary>
		public int progress;
		/// <summary>
        /// 创建时间(毫秒时间戳)
        /// </summary>
		public long createTime;
		/// <summary>
        /// 任务状态
        /// </summary>
		public QuestStatus status;
		/// <summary>
        /// 父任务配置id
        /// </summary>
		public int parentCid;
		/// <summary>
        /// 子任务状态信息(完成和失败的)
        /// </summary>
        private Dictionary<int, int> m_childStatusMap;
		/// <summary>
        /// 已领奖阶段
        /// </summary>
		public int rewardPhase;
		
		
        public Dictionary<int, int> childStatusMap
        {
            get
            {
                if(m_childStatusMap == null)
                {
                    m_childStatusMap = new();
                }
                return m_childStatusMap;
            }
            private set => m_childStatusMap = value;
        }
        public Dictionary<int, int> unsafe_childStatusMap
        {
        	get => m_childStatusMap;
        	set => m_childStatusMap = value;
        }
		
		/*-- constructors --*/
		public QuestPOD() {}
		public QuestPOD(long id, int cid, int progress, long createTime, QuestStatus status, int parentCid, Dictionary<int, int> childStatusMap, int rewardPhase) {
			this.id = id;
			this.cid = cid;
			this.progress = progress;
			this.createTime = createTime;
			this.status = status;
			this.parentCid = parentCid;
			this.m_childStatusMap = childStatusMap;
			this.rewardPhase = rewardPhase;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_long(id);
            _out.Write_int(cid);
            _out.Write_int(progress);
            _out.Write_long(createTime);
            _out.Write_byte((sbyte)status);
            _out.Write_int(parentCid);
            _out.Write_map_int_int(m_childStatusMap);
            _out.Write_int(rewardPhase);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            id = _in.Read_long();
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            progress = _in.Read_int();
            if(!_in.HasRemaining()) return;
            createTime = _in.Read_long();
            if(!_in.HasRemaining()) return;
            status = (QuestStatus)_in.Read_byte();
            if(!_in.HasRemaining()) return;
            parentCid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_childStatusMap = _in.Read_map_int_int();
            if(!_in.HasRemaining()) return;
            rewardPhase = _in.Read_int();
        }
		
		public QuestPOD Clone() {
            QuestPOD o = DynamicFactory();
            o.id = id;
            o.cid = cid;
            o.progress = progress;
            o.createTime = createTime;
            o.status = status;
            o.parentCid = parentCid;
            if (m_childStatusMap != null) {
                o.m_childStatusMap = new (m_childStatusMap);
            }
            o.rewardPhase = rewardPhase;
            return o;
        }
        
        public void Clear() {
            id = default;
            cid = default;
            progress = default;
            createTime = default;
            status = default;
            parentCid = default;
            m_childStatusMap = default;
            rewardPhase = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "QuestPOD [";
			str += "id=";
			str += id;
			str += ", cid=";
			str += cid;
			str += ", progress=";
			str += progress;
			str += ", createTime=";
			str += createTime;
			str += ", status=";
			str += status;
			str += ", parentCid=";
			str += parentCid;
			str += ", childStatusMap=";
			str += m_childStatusMap.ToString<int, int>();
			str += ", rewardPhase=";
			str += rewardPhase;
			str += "]";
			return str;
		}
		
	}
}